package battleofthejavasea;

import java.io.FileNotFoundException;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.loaders.*;
import com.sun.j3d.loaders.objectfile.ObjectFile;

public class SeaObject {

    //Adiciona o mar na origem
    public BranchGroup createSea() throws FileNotFoundException
    {
        //Branchgroup de retorno
        BranchGroup branchGroup = new BranchGroup();

        //Loader para o objeto
        ObjectFile objectFile = new ObjectFile();
        Scene scene = objectFile.load("sea.obj");

        //Transform3D
        Transform3D transform3D = new Transform3D();

        //TransformGroup criado com o objeto transform
        TransformGroup transformGroup = new TransformGroup(transform3D);

        transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        transformGroup.addChild(scene.getSceneGroup());
        transform3D.setIdentity();

        //Centraliza
        transform3D.setTranslation(new Vector3d(0, 0, 0));

        transformGroup.setTransform(transform3D);

        branchGroup.addChild(transformGroup);
        branchGroup.compile();

        return branchGroup;
    }
}
